// @flow

export const SAVE_HISTORY = 'SAVE_HISTORY'

type Action = {
  type: string,
  history: Object
}

export const saveHistory = (history: Object) => {
  return {
    type: SAVE_HISTORY,
    history
  }
}

const ACTION_HANDLERS = {
  [SAVE_HISTORY]: (state, { history }: Action) => Object.assign({}, state, {
    history: history
  })
}

type State = Object

const initialState = {
  history: {}
}

export default function homeHitoryReducer (state: State = initialState, action: Action) {
  const handler = ACTION_HANDLERS[action.type]

  return handler ? handler(state, action) : state
}
